package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.Ce;
import com.ruoyi.system.service.ICeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 测试Controller
 * 
 * @author ruoyi
 * @date 2022-11-29
 */
@Controller
@RequestMapping("/system/ce")
public class CeController extends BaseController
{
    private String prefix = "system/ce";

    @Autowired
    private ICeService ceService;

    @RequiresPermissions("system:ce:view")
    @GetMapping()
    public String ce()
    {
        return prefix + "/ce";
    }

    /**
     * 查询测试列表
     */
    @RequiresPermissions("system:ce:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Ce ce)
    {
        startPage();
        List<Ce> list = ceService.selectCeList(ce);
        return getDataTable(list);
    }

    /**
     * 导出测试列表
     */
    @RequiresPermissions("system:ce:export")
    @Log(title = "测试", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Ce ce)
    {
        List<Ce> list = ceService.selectCeList(ce);
        ExcelUtil<Ce> util = new ExcelUtil<Ce>(Ce.class);
        return util.exportExcel(list, "测试数据");
    }

    /**
     * 新增测试
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存测试
     */
    @RequiresPermissions("system:ce:add")
    @Log(title = "测试", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Ce ce)
    {
        return toAjax(ceService.insertCe(ce));
    }

    /**
     * 修改测试
     */
    @RequiresPermissions("system:ce:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        Ce ce = ceService.selectCeById(id);
        mmap.put("ce", ce);
        return prefix + "/edit";
    }

    /**
     * 修改保存测试
     */
    @RequiresPermissions("system:ce:edit")
    @Log(title = "测试", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Ce ce)
    {
        return toAjax(ceService.updateCe(ce));
    }

    /**
     * 删除测试
     */
    @RequiresPermissions("system:ce:remove")
    @Log(title = "测试", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ceService.deleteCeByIds(ids));
    }
}
